package com.cloudeasy.core.config;

import com.cloudeasy.config.properties.CloudEasyProperties;
import com.cloudeasy.core.registry.RegistryCenterFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.net.InetAddress;

/**
 * Create By 郭金宝 on 2019/1/16.<br>
 */
@Component
@Order
@Slf4j
public class ZookeeperInitRunner implements CommandLineRunner {
    @Resource
    private CloudEasyProperties cloudEasyProperties;
    @Value("${spring.application.name}")
    private String applicationName;

    /**
     * Run.
     *
     * @param args the args
     *
     * @throws Exception the exception
     */
    @Override
    public void run(String... args) throws Exception {
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        log.info("###ZookeeperInitRunner，init. HostAddress={}, applicationName={}", hostAddress, applicationName);
        RegistryCenterFactory.startup(cloudEasyProperties, hostAddress, applicationName);
        log.info("###ZookeeperInitRunner，finish<<<<<<<<<<<<<");
    }

}